'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 11_simple_chain.py
* @Time: 2025/10/23
* @All Rights Reserve By Brtc
'''
from typing import Any

import dotenv
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

dotenv.load_dotenv()
class Chain:
    _steps:list=[]

    def __init__(self,steps:list):
        self._steps=steps

    def invoke(self, input:Any)->Any:
        output=input
        for step in self._steps:
            output=step.invoke(output)
            print('步骤:', step)
            print('输出:',output)
            print("=========================")
        return output

prompt = ChatPromptTemplate.from_template("{query}")

llm = ChatOpenAI(model="gpt-4o-mini")
parser = StrOutputParser()
chain = Chain(steps=[prompt, llm, parser])

print(chain.invoke({"query":"你好，你是？"}))

